home *** CD-ROM | disk | FTP | other *** search
/ Internet Tools (InfoMagic) / Internet Tools.iso / news / moderating / autoreply.shar.Z / autoreply.shar
Internet Message Format  |  1994-05-06  |  8KB

  1. From tale@uunet.uu.net Thu Oct 14 10:34:28 1993
  2. Received: from uunet.uu.net by sparky.Sterling.COM (5.65c/IDA-1.4.4)
  3.     id AA09562; Thu, 14 Oct 1993 10:34:26 -0500
  4. Return-Path: <tale@uunet.uu.net>
  5. Received: by rodan.UU.NET (5.61/UUNET-mail-drop)
  6.     id AA22594; Thu, 14 Oct 93 11:24:36 -0400
  7. Received: by rodan.UU.NET (5.61/UUNET-mail-drop)
  8.     id AA22584; Thu, 14 Oct 93 11:24:33 -0400
  9. Date: Thu, 14 Oct 93 11:24:33 -0400
  10. From: tale@uunet.uu.net (David C Lawrence)
  11. Message-Id: <9310141524.AA22584@rodan.UU.NET>
  12. To: moderators@uunet.uu.net
  13. Subject: Re: Procmail question and a little comment
  14. In-Reply-To: <9310141312.AA20784@top.magnus.acs.ohio-state.edu>
  15. References: <9310141312.AA20784@top.magnus.acs.ohio-state.edu>
  16. Status: OR
  17.  
  18. Coyt D Watters writes:
  19. > First of all, can anyone on the Moderator's List point me to a decent
  20. > instruction manual for .procmail?  The man pages don't do it for me
  21. > (I'm no Unix wiz).
  22.  
  23. I don't know of one, but you can try asking the author:
  24. berg@pool.informatik.rwth-aachen.de (Stephen R. van den Berg)
  25.  
  26. There is also a mailing list:  procmail-request@informatik.rwth-aachen.de
  27.  
  28. > All I really want to do is send a canned reply back to the send that hir
  29. > post to rec.games.frp.announce has been recieved and will be reviewed.
  30.  
  31. I sent something like this to the moderator's list previously.  I'll
  32. append a version of it.  It also uses perl.
  33.  
  34. > I'm already using it to do sorting and filing (had to add a Moderators
  35. > mailbox this morning, 53 message in 24h, sheesh).
  36.  
  37. Oh, this makes it a little more tricky, but not much.  The procmailrc
  38. in the example delivers any mail that doesn't get an autoreply to the
  39. spool folder, and then runs the rest through a filter to fix the
  40. "headers in the body" problem, then tries the auto-replies.  Depending
  41. on the nature of your filing, you can either just hang it off the
  42. auto-reply catches or might have to restructure how you handle
  43. ignoring some addresses for the reply.
  44.  
  45. #! /bin/sh
  46. # This is a shell archive.  Remove anything before this line, then feed it
  47. # into a shell via "sh file" or similar.  To overwrite existing files,
  48. # type "sh file -c".
  49. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  50. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  51. # Contents:  arep headstrip procmailrc
  52. # Wrapped by tale@rodan on Thu Oct 14 11:21:18 1993
  53. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  54. echo If this archive is complete, you will see the following message:
  55. echo '          "shar: End of archive."'
  56. if test -f 'arep' -a "${1}" != "-c" ; then 
  57.   echo shar: Will not clobber existing file \"'arep'\"
  58. else
  59.   echo shar: Extracting \"'arep'\" \(2729 characters\)
  60.   sed "s/^X//" >'arep' <<'END_OF_FILE'
  61. X#!/bin/perl
  62. X#
  63. X# based on a shell script by scott hazen mueller
  64. X# tale, july 1993
  65. X#
  66. X# Auto-reply to an email message.  $1 is the name of a reply form
  67. X# letter file to use.  Input is an email message to search for the
  68. X# reply address.  Try to avoid sending the same reply to the same
  69. X# recipient twice in a one-week interval, just like vacation
  70. X
  71. X#customise:
  72. X$arep = "/home/tale/.arep";
  73. X$interval = 60 * 60 * 24 * 7;  # seconds between auto-replies
  74. X$msgdir = "/home/tale/forms/auto-replies";
  75. X$sendmail = "/usr/lib/sendmail";
  76. X$from = 'David C Lawrence <tale@ten.uu.net>';
  77. X#end
  78. X
  79. Xdie "usage: $0 reply-file" if $#ARGV != 0;
  80. X
  81. X$cutoff = time - $interval;
  82. X
  83. Xdbmopen(%arep, $arep, 0666) || die "$0: dbmopen $arep: $!\n";
  84. X
  85. X$* = 1;         # let ^ and $ work with newlines embedded in input.
  86. X
  87. X$/ = "";        # read until empty line mode
  88. X$_ = <STDIN>;   # get the whole header
  89. Xs/\n\s+/ /g;    # rejoin continued lines
  90. X
  91. X# save the subject; we will trounce on $_ in a moment.
  92. X($subject) = /^Subject: (.*)/i;
  93. X
  94. X# try to get reply address.  same basic heuristics as gene/scott's "reply"
  95. X# prog, but doesn't clean it up with fixfrom like the shell script did.
  96. X/^Reply-To: (.+)/i || /^From: (.+)/i || /^Return-Path: (.+)/i || /^From (\S+)/i;
  97. X
  98. X# try to ditch an obvious comment.  it could possibly have a <...> in it.
  99. X# not rfc 822 strict with matching or quoted parens.
  100. X($_ = $1) =~ s/\(.*\)//;
  101. X
  102. X# takes either the "Comment <address>" or "address" (parenthetical
  103. X# comment was just stripped above) to get the essential address.
  104. X# this will fail for some various perversities of RFC 822, like quoted
  105. X# spaces in local address parts.  rfc 822 syntax is the work of the
  106. X# devil, not a programmer. 
  107. X(($reply) = /<(.+)>/) || (($reply) = /^\s*(\S+)/);
  108. X
  109. X# do we need to send a reply?
  110. Xexit 0 if $arep{$reply} && $arep{$reply} > $cutoff;
  111. X
  112. X# Send the reply.
  113. X# First, touch up the subject
  114. X$subject = 'Re: your mail' if !$subject;
  115. X$subject =~ s/^/Re: / if $subject !~ /^\s*Re:/i;
  116. X$subject = '[auto-reply] ' . $subject;
  117. X
  118. X# Next, get the message to send.
  119. Xopen(MSG, "<$msgdir/$ARGV[0]") || die "$0: open $msgdir/$ARGV[0]: $!\n";
  120. Xundef $/;       # slurp the whole thing in
  121. Xchop($msg = <MSG>);
  122. X
  123. Xopen(MAIL, "| $sendmail $reply") || die "$0: calling sendmail: $!\n";
  124. X
  125. Xprint MAIL <<EOF;
  126. XFrom: $from
  127. XTo: $reply
  128. XSubject: $subject
  129. X
  130. XNote of the week:  I have been really hit with work for UUNET, so my
  131. Xpersonal mailbox has filled a bit.  Expect delays.
  132. X
  133. XThis is an automatically generated reply to a message from you which
  134. Xlanded in my mailbox.  Auto-replies of all forms from me will only be
  135. Xsent once per week to any given address.  Use a Return-Receipt-To
  136. Xheader if you want confirmation of specific mail messages you send to me.
  137. X
  138. X$msg
  139. XEOF
  140. X
  141. X$arep{$reply} = time;
  142. Xexit 0;
  143. END_OF_FILE
  144.   if test 2729 -ne `wc -c <'arep'`; then
  145.     echo shar: \"'arep'\" unpacked with wrong size!
  146.   fi
  147.   chmod +x 'arep'
  148.   # end of 'arep'
  149. fi
  150. if test -f 'headstrip' -a "${1}" != "-c" ; then 
  151.   echo shar: Will not clobber existing file \"'headstrip'\"
  152. else
  153.   echo shar: Extracting \"'headstrip'\" \(342 characters\)
  154.   sed "s/^X//" >'headstrip' <<'END_OF_FILE'
  155. X#! /bin/sed -f
  156. X# the script is for use with a procmail recipe that has determined
  157. X# that the real news headers for a submission to a moderated group
  158. X# appear to lead the body of the message.  it gets them into the 
  159. X# mail headers without loss of information.
  160. X
  161. Xs/^From: /X-Mail-Submission-From: /
  162. X/^$/ {
  163. X  N;s/^.//
  164. X  : ptoeof
  165. X  n
  166. X  b ptoeof
  167. X}
  168. END_OF_FILE
  169.   if test 342 -ne `wc -c <'headstrip'`; then
  170.     echo shar: \"'headstrip'\" unpacked with wrong size!
  171.   fi
  172.   chmod +x 'headstrip'
  173.   # end of 'headstrip'
  174. fi
  175. if test -f 'procmailrc' -a "${1}" != "-c" ; then 
  176.   echo shar: Will not clobber existing file \"'procmailrc'\"
  177. else
  178.   echo shar: Extracting \"'procmailrc'\" \(1139 characters\)
  179.   sed "s/^X//" >'procmailrc' <<'END_OF_FILE'
  180. X# use with .forward file:
  181. X# "|IFS=' ';exec /usr/local/bin/procmail -t #tale"
  182. X
  183. XCOMSAT=no
  184. XBIN=$HOME/bin
  185. X
  186. X# conditions for which there should be never be an auto-reply.
  187. X# it is only here to get procmail to deliver the mail then quit
  188. X# out of the procmailrc processing.
  189. X# all local addresses are fully qualified when procmail is called.
  190. X::
  191. X*^((Resent-)?From:.*(uu\.net|moraes@deshaw\.com|D\.W\.Wright@bnr\.co\.uk|\
  192. Xurlichs@smurf\.sub\.org)|Precedence: (bulk|junk))
  193. X$ORGMAIL
  194. X
  195. X# try to identify moderated posts with headers in the start of the body.
  196. X# the ^^ anchors it at the start of the body, the ($)* skips leading empty
  197. X# lines, the (.+$)* limits the search for the header up to the next empty
  198. X# line.  
  199. X:Bfw
  200. X* ^^($)*(.+$)*Newsgroups: .
  201. X* ^^($)*(.+$)*Path: .
  202. X* ^^($)*(.+$)*From: .
  203. X* ^^($)*(.+$)*Date: .
  204. X* ^^($)*(.+$)*Subject: .
  205. X* ^^($)*(.+$)*Message-ID: .
  206. X| $BIN/headstrip
  207. X
  208. X:c:arep
  209. X*^TO.*news?groups
  210. X| $BIN/arep news.announce.newgroups
  211. X
  212. X:c:arep
  213. X*^TO.*news-lists
  214. X| $BIN/arep news.lists
  215. X
  216. X:c:arep
  217. X*^TO.*group-advice
  218. X| $BIN/arep group-advice
  219. X
  220. X:c:arep
  221. X*^TO.*moderators-request
  222. X| $BIN/arep moderators-request
  223. X
  224. X:c:arep
  225. X*^TO.*tale
  226. X| $BIN/arep tale
  227. END_OF_FILE
  228.   if test 1139 -ne `wc -c <'procmailrc'`; then
  229.     echo shar: \"'procmailrc'\" unpacked with wrong size!
  230.   fi
  231.   # end of 'procmailrc'
  232. fi
  233. echo shar: End of archive.
  234. exit 0
  235.  
  236.